package com.jian.android.autojipai.app.helper;

import android.util.Log;

import com.jian.android.autojipai.app.App;
import com.jian.android.autojipai.data.bean.EventBusOb;
import com.jian.android.autojipai.data.bean.Poker;
import com.jian.android.autojipai.data.bean.PokerDetection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.greenrobot.eventbus.EventBus;

public class PokerDataHandleTool {
    private List<PokerDetection> allPokerDetectionList;

    public static class PokerDataHandleToolInstance {
        private static final PokerDataHandleTool instance = new PokerDataHandleTool();

        private PokerDataHandleToolInstance() {
        }
    }

    private PokerDataHandleTool() {
        this.allPokerDetectionList = new ArrayList();
    }

    public static PokerDataHandleTool getInstance() {
        return PokerDataHandleToolInstance.instance;
    }

    public void setAllPokerDataIsEmpty() {
        List<PokerDetection> list = this.allPokerDetectionList;
        if (list != null) {
            list.clear();
        }
    }

    public void handPokerData(List<PokerDetection> list) {
        Log.e("---TAG",  "handPokerData"+list.size());

        try {
            this.allPokerDetectionList.addAll(list);
            HashSet hashSet = new HashSet(this.allPokerDetectionList);
            this.allPokerDetectionList.clear();
            this.allPokerDetectionList.addAll(hashSet);
            String str = App.type;
            List<Poker> autoPaoDeKuaiPokers ;
            if ("跑的快[16张]".equals(str)) {
                autoPaoDeKuaiPokers = Poker.getAutoPaoDeKuaiPokers16(1);
            }else if ("跑的快[15张]".equals(str)) {
                autoPaoDeKuaiPokers = Poker.getAutoPaoDeKuaiPokers15(1);
            }else if ("1副牌".equals(str)) {
                autoPaoDeKuaiPokers = Poker.getAutoPokers1(1);
            }else {
                autoPaoDeKuaiPokers = new ArrayList<>();
            }

            int size = autoPaoDeKuaiPokers.size();
            for (int i = 0; i < this.allPokerDetectionList.size(); i++) {
                PokerDetection pokerDetection = this.allPokerDetectionList.get(i);
                for (int j = 0; j < size ; j++){
                    Poker poker = autoPaoDeKuaiPokers.get(j);
                    if (pokerDetection.getLable().startsWith(poker.getType())) {
                        int number = poker.getNumber();
                        if (number >= 1) {
                            poker.setNumber(number - 1);
                            if (poker.getNumber() == 0) {
                                poker.setHaveNumber(false);
                            }
                        }
                    }
                }
            }

            EventBus.getDefault().post(new EventBusOb("updateUI", autoPaoDeKuaiPokers));
        } catch (Exception e) {
            e.printStackTrace();
            LogTool.getInstance().printLog("---TAG", "去重发生异常：" + e.getMessage());
//            CrashReport.postCatchedException(e);
        }
    }
}
